<style lang="less">
</style>
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <Export ref="export"></Export>
    <card>
      <Row>
        <Col span="3" align="center" style="line-height: 2;">导出设置编号</Col>
        <Col span="4">
          <Input v-model="searchData.export_code" style="width: 80%"  placeholder="请输入导出数据库标识"></Input>
        </Col>
        <Col span="3" align="center" style="line-height: 2;">导出设置名称</Col>
        <Col span="4">
          <Input v-model="searchData.export_name" style="width: 80%"  placeholder="请输入导出数据库名称"></Input>
        </Col>
        <Col span="2" align="center" style="line-height: 2;">状态</Col>
        <Col span="3">
         <Select v-model="searchData.export_state" style="width: 70%">
           <Option value="">全部</Option>
           <Option value="0">未启用</Option>
           <Option value="1">已启用</Option>
         </Select>
        </Col>
        <Col span="3">
          <Button type="primary" icon="ios-search"  @click="init">搜索</Button>
        </Col>
      </Row>
    </card>
    <card style="margin-top: 1%">
      <Row>
        <Col span="3">
          <Button type="primary" icon="md-add-circle" @click="addExportSet">添加</Button>
        </Col>
        <Col span="3">
          <Button type="primary" icon="md-add-circle" @click="exportStart">导出</Button>
        </Col>
      </Row>
      <Row>
        <Col span="24">
          <Table border stripe :columns="columns" ref="selection" :data="dataList" style="margin-top: 1%;">
          </Table>
        </Col>
      </Row>
      <Row type="flex" justify="end" style="margin-top: 1%">
        <Page :current="pageNo" :total="totalnum" show-sizer :page-size="pageSize"
              show-total @on-change="changePageNo" @on-page-size-change="changePagesize"/>
      </Row>
    </card>
    <Modal v-model="modal.show" :title="modal.title" width="360">
      <Form :model="formData" :label-width="100">
        <FormItem label="导出设置名称">
          <Input v-model="formData.export_name" ></Input>
        </FormItem>
        <FormItem label="导出数据库">
          <Select v-model="export_database" filterable transfer="" >
            <Option :value="item.export_database"  v-for="item in dataBaseBsList" v-bind:key="item.export_database">{{item.export_database_name + item.export_database}}</Option>
          </Select>
        </FormItem>
        <FormItem label="导出数据库主从">
          <RadioGroup v-model="formData.export_database_type" >
            <Radio label="master" border>master</Radio>
            <Radio label="slave" border>slave</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="导出表主表名">
          <Select v-model="formData.export_master_table" filterable transfer="">
            <Option :value="item.export_database_table"  v-for="item in dataBaseBsTableList" v-bind:key="item.export_database_table">{{item.export_database_table}}</Option>
          </Select>
        </FormItem>
        <FormItem label="主表别名">
          <Input v-model="formData.export_master_table_alias"></Input>
        </FormItem>
        <FormItem label="table_schema">
          <Input v-model="formData.table_schema"></Input>
        </FormItem>
        <FormItem label="页面标识">
          <Input v-model="formData.url_code"></Input>
        </FormItem>
        <FormItem v-if="modal.type === '2'" label="状态">
          <RadioGroup v-model="formData.export_state" >
            <Radio label="1" border>启用</Radio>
            <Radio label="0" border>未启用</Radio>
          </RadioGroup>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="modal.show = false">取消</Button>
        <Button v-if="modal.type === '1'" type="primary" @click="addExportSetOk">保存</Button>
        <Button v-if="modal.type === '2'" type="primary" @click="updateExportSetOk">保存</Button>
      </div>
    </Modal>
    <Modal v-model="modal1.show" :title="modal1.title" width="360">
      <Form :model="formData1" :label-width="120">
        <FormItem label="导出列表名">
          <Select v-model="export_table" filterable transfer="">
            <Option :value="item.tablename"  v-for="item in tableNameList" v-bind:key="item.tablename">{{item.tablename}}</Option>
          </Select>
        </FormItem>
        <FormItem label="导出查询列">
          <Select v-model="export_select_column" filterable transfer="" >
            <Option :value="item.COLUMN_NAME"  v-for="item in fieldList" v-bind:key="item.COLUMN_NAME">{{item.COLUMN_NAME + '\t' + item.COLUMN_COMMENT}}</Option>
          </Select>
        </FormItem>
        <FormItem label="导出列">
          <Input v-model="export_column"></Input>
        </FormItem>
        <FormItem label="导出列别名">
          <Input v-model="export_column_alias"></Input>
        </FormItem>
        <FormItem label="导出列标题">
          <Input v-model="formData1.export_column_name"></Input>
        </FormItem>
        <FormItem label="导出列字典">
          <Input v-model="formData1.export_column_dict"></Input>
        </FormItem>
        <FormItem label="导出列SQL">
          <Input v-model="formData1.export_column_sql"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="modal1.show = false">取消</Button>
        <Button type="primary" @click="addExportSetDetailOk">保存</Button>
      </div>
    </Modal>
    <Modal v-model="modal2.show" :title="modal2.title" width="360">
      <Form :model="formData2">
        <FormItem label="条件列">
          <Select v-model="formData2.export_column" filterable transfer="" @on-change="columnOnChange">
            <Option :value="item.export_column"  v-for="item in dataList2" v-bind:key="item.id">{{item.export_column +'\t'+ item.export_column_name}}</Option>
          </Select>
        </FormItem>
        <FormItem label="条件">
          <Input v-model="formData2.export_condition"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="modal2.show = false">取消</Button>
        <Button type="primary" @click="addExportSetConditionOk">保存</Button>
      </div>
    </Modal>
    <Modal v-model="infoModal.show" :title="infoModal.title" width="90%">
<!--      <card>-->
<!--        <Row>-->
<!--          <Col span="3" align="center" style="line-height: 2;">导出数据库表</Col>-->
<!--          <Col span="4">-->
<!--            <Input v-model="searchData1.export_database_table" style="width: 80%"  placeholder="请输入导出数据库表"></Input>-->
<!--          </Col>-->
<!--          <Col span="3" align="center" style="line-height: 2;">导出数据库表名称</Col>-->
<!--          <Col span="4">-->
<!--            <Input v-model="searchData1.export_database_table_name"  style="width: 80%"  placeholder="请输入导出数据库表名称"></Input>-->
<!--          </Col>-->
<!--          <Col span="2" align="center" style="line-height: 2;">状态</Col>-->
<!--          <Col span="3">-->
<!--            <Select v-model="searchData1.export_state" style="width: 70%">-->
<!--              <Option value="">全部</Option>-->
<!--              <Option value="0">未启用</Option>-->
<!--              <Option value="1">已启用</Option>-->
<!--            </Select>-->
<!--          </Col>-->
<!--          <Col span="3">-->
<!--            <Button type="primary" icon="ios-search" @click="getExportSetSubList">搜索</Button>-->
<!--          </Col>-->
<!--        </Row>-->
<!--      </card>-->
      <card style="margin-top: 1%">
        <Row>
          <Col span="3">
            <Button type="primary" icon="md-add-circle" @click="addSubTable">添加</Button>
          </Col>
        </Row>
        <Row>
          <Col span="24">
            <Table border stripe :columns="columns1" ref="selection" :data="dataList1" style="margin-top: 1%;">
              <template slot-scope="{ row }" slot="export_sub_table">
                <Select v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_table" filterable transfer="">
                  <Option :value="item.export_database_table"  v-for="item in dataBaseBsTableList" v-bind:key="item.export_database_table">{{item.export_database_table}}</Option>
                </Select>
<!--                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_table"></Input>-->
                <span  v-if="row.disabled">{{row.export_sub_table}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_sub_table_alias">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_table_alias"></Input>
                <span  v-if="row.disabled">{{row.export_sub_table_alias}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_sub_join">
                <Select v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_join" filterable transfer="">
                  <Option value="inner join">inner join</Option>
                  <Option value="left join">left join</Option>
                  <Option value="right join">right join</Option>
                </Select>
<!--                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_join"></Input>-->
                <span  v-if="row.disabled">{{row.export_sub_join}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_sub_join_on">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_join_on"></Input>
                <span  v-if="row.disabled">{{row.export_sub_join_on}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_state">
                <i-switch v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_state" true-value="1" false-value="0" true-color="#13ce66" false-color="#ff4949" size="large">
                  <span  slot="open">启用</span>
                  <span  slot="close">关闭</span>
                </i-switch>
                <span  v-if="row.disabled">{{row.state}}</span>
              </template>
            </Table>
          </Col>
        </Row>
<!--        <Row type="flex" justify="end" style="margin-top: 1%">-->
<!--          <Page :current="pageNo1" :total="totalnum1" show-sizer :page-size="pageSize1"-->
<!--                show-total @on-change="changePageNo1" @on-page-size-change="changePagesize1"/>-->
<!--        </Row>-->
      </card>
    </Modal>
    <Modal v-model="infoModal1.show" :title="infoModal1.title" width="90%">
      <card style="margin-top: 1%">
        <Row>
          <Col span="3">
            <Button type="primary" icon="md-add-circle" @click="addSetDetail">添加</Button>
          </Col>
        </Row>
        <Row>
          <Col span="24">
            <Table border stripe :columns="columns2" ref="selection" :data="dataList2" style="margin-top: 1%;">
              <template slot-scope="{ row }" slot="export_table">
                <Select v-if="!row.disabled" :disabled="row.disabled" v-model="export_table" filterable transfer="" @on-change="indexChange(index)">
                  <Option :value="item.tablename"  v-for="item in tableNameList" v-bind:key="item.tablename">{{item.tablename}}</Option>
                </Select>
                <!--                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_sub_table"></Input>-->
                <span  v-if="row.disabled">{{row.export_table}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_column">
                <Select v-if="!row.disabled" :disabled="row.disabled" v-model="export_column" filterable transfer="" >
                  <Option :value="item.COLUMN_NAME"  v-for="item in fieldList" v-bind:key="item.COLUMN_NAME">{{item.COLUMN_NAME}}</Option>
                </Select>
                <span  v-if="row.disabled">{{row.export_column}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_column_alias">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_column_alias"></Input>
                <span  v-if="row.disabled">{{row.export_column_alias}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_column_name">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_column_name"></Input>
                <span  v-if="row.disabled">{{row.export_column_name}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_column_dict">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_column_dict"></Input>
                <span  v-if="row.disabled">{{row.export_column_dict}}</span>
              </template>
              <template slot-scope="{ row }" slot="export_column_sql">
                <Input v-if="!row.disabled" :disabled="row.disabled" v-model="row.export_column_sql"></Input>
                <span  v-if="row.disabled">{{row.export_column_sql}}</span>
              </template>
            </Table>
          </Col>
        </Row>
        <!--        <Row type="flex" justify="end" style="margin-top: 1%">-->
        <!--          <Page :current="pageNo1" :total="totalnum1" show-sizer :page-size="pageSize1"-->
        <!--                show-total @on-change="changePageNo1" @on-page-size-change="changePagesize1"/>-->
        <!--        </Row>-->
      </card>
    </Modal>
    <Modal v-model="infoModal2.show" :title="infoModal2.title" width="90%">
      <card style="margin-top: 1%">
        <Row>
          <Col span="3">
            <Button type="primary" icon="md-add-circle" @click="addSetCondition">添加</Button>
          </Col>
        </Row>
        <Row>
          <Col span="24">
            <Table border stripe :columns="columns3" ref="selection" :data="dataList3" style="margin-top: 1%;">
            </Table>
          </Col>
        </Row>
        <!--        <Row type="flex" justify="end" style="margin-top: 1%">-->
        <!--          <Page :current="pageNo1" :total="totalnum1" show-sizer :page-size="pageSize1"-->
        <!--                show-total @on-change="changePageNo1" @on-page-size-change="changePagesize1"/>-->
        <!--        </Row>-->
      </card>
    </Modal>
  </div>
</template>
<script>
import {
  insertExportSet,
  getDataBaseNameList,
  getExportSetSubList,
  updateExportSetSub,
  deleteExportSetSub,
  insertExportSetSub,
  getExportSetPageList,
  getExportDataBaseBsList,
  getExportDataBaseBsTableList,
  deleteExportSet,
  updateExportSet,
  getExportSetDetailList,
  getExportSetTableNameList,
  getTableFieldList,
  insertExportSetDetail,
  deleteExportSetDetail,
  getExportSetConditionList,
  insertExportSetCondition,
  deleteExportSetCondition } from '@/api/eventlist'
import Export from '../export-compoments'
export default {
  components: {
    Export
  },
  data () {
    return {
      export_column_alias: '',
      export_select_column: '',
      tableObj: {},
      index: 0,
      export_database: '',
      export_table: '',
      export_column: '',
      export_tableObj: {},
      dataBaseBsList: [],
      dataBaseBsTableList: [],
      dataBaseBsTableList1: [],
      tableNameList: [],
      fieldList: [],
      disabled: true,
      searchData: {},
      searchData1: {},
      row: {},
      export_database_id: '',
      tableData: [],
      targetKeys: [],
      listStyle: {
        width: '40%',
        height: '300px'
      },
      modal: {
        title: '',
        show: false,
        type: ''
      },
      modal1: {
        title: '导出设置字段添加',
        show: false,
        type: ''
      },
      modal2: {
        title: '导出设置条件添加',
        show: false,
        type: ''
      },
      infoModal: {
        title: '导出设置子表明细',
        show: false,
        type: ''
      },
      infoModal1: {
        title: '导出设置字段明细',
        show: false,
        type: ''
      },
      infoModal2: {
        title: '导出设置条件明细',
        show: false,
        type: ''
      },
      addTableModal: {
        title: '添加导出数据库表',
        show: false,
        type: ''
      },
      formData: {},
      formData1: {},
      formData2: {},
      totalnum: 0,
      pageNo: 1,
      pageSize: 10,
      totalnum1: 0,
      pageNo1: 1,
      pageSize1: 10,
      columns: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '导出设置编号', tooltip: true, width: 150, key: 'export_code', align: 'center' },
        { title: '导出设置名称', tooltip: true, width: 150, key: 'export_name', align: 'center' },
        { title: '导出数据库标识', tooltip: true, width: 130, key: 'export_database', align: 'center' },
        { title: '导出数据库主从', tooltip: true, width: 130, key: 'export_database_type', align: 'center' },
        { title: '导出表主表名', tooltip: true, width: 150, key: 'export_master_table', align: 'center' },
        { title: '主表别名', tooltip: true, width: 120, key: 'export_master_table_alias', align: 'center' },
        { title: 'table_schema', tooltip: true, width: 150, key: 'table_schema', align: 'center' },
        { title: '页面标识', tooltip: true, width: 150, key: 'url_code', align: 'center' },
        { title: '状态', key: 'state', width: 150, align: 'center' },
        { title: '操作',
          align: 'center',
          fixed: 'right',
          width: 180,
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.infoModal.show = true
                    this.row = params.row
                    this.dataBaseBsTableList = []
                    params.row.id = ''
                    this.findTable(params.row)
                    this.getExportSetSubList(params.row)
                  }
                }
              }, '子表'),
              h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.infoModal1.show = true
                    this.row = params.row
                    this.dataBaseBsTableList = []
                    params.row.id = ''
                    // this.findTable(params.row)
                    this.getExportSetTableNameList(params.row)
                    this.getExportSetDetailList(params.row)
                  }
                }
              }, '字段'),
              h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.infoModal2.show = true
                    this.row = params.row
                    this.dataBaseBsTableList = []
                    params.row.id = ''
                    // this.findTable(params.row)
                    this.getExportSetConditionList(params.row)
                    this.getExportSetDetailList(params.row)
                  }
                }
              }, '条件'),
              h('Button', {
                props: { type: 'success', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.formData = params.row
                    this.export_database = params.row.export_database
                    console.log(this.formData)
                    this.modal.title = '编辑导出数据库'
                    this.modal.show = true
                    this.modal.type = '2'
                  }
                }
              }, '编辑'),
              h('Button', {
                props: { type: 'error', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.deleteExportSetOk(params.row)
                  }
                }
              }, '删除'))
            return h('div', temp)
          }
        }
      ],
      dataList: [],
      columns1: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '导出设置编号', key: 'export_code', align: 'center' },
        { title: '导出表子表名', slot: 'export_sub_table', align: 'center' },
        { title: '子表别名', slot: 'export_sub_table_alias', align: 'center' },
        { title: '关联关系', slot: 'export_sub_join', align: 'center' },
        { title: '关联条件', slot: 'export_sub_join_on', align: 'center' },
        { title: '操作',
          align: 'center',
          render: (h, params) => {
            let temp = []
            if (params.row.disabled) {
              temp.push(
                h('Button', {
                  props: { type: 'success', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      params.row.disabled = false
                      // this.formData1 = params.row
                      // console.log(params)
                      // this.modal1.title = '编辑导出数据库表'
                      // this.modal1.show = true
                      // this.modal1.type = '2'
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: { type: 'error', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.deleteExportSetSubOk(params.row)
                    }
                  }
                }, '删除')
              )
            } else if (params.row.id) {
              temp.push(h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.formData1 = params.row
                    this.updateExportSetSubOk()
                    params.row.disabled = true
                    // console.log(params)
                    // this.modal.title = '编辑导出数据库'
                    // this.modal.show = true
                    // this.modal.type = '2'
                  }
                }
              }, '保存'),
              h('Button', {
                props: { type: 'success', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.getExportSetSubList()
                    params.row.disabled = true
                  }
                }
              }, '取消'))
            } else {
              temp.push(h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.formData1 = params.row
                    this.addExportSetSubOk()
                    params.row.disabled = true
                    // console.log(params)
                    // this.modal.title = '编辑导出数据库'
                    // this.modal.show = true
                    // this.modal.type = '2'
                  }
                }
              }, '保存'),
              h('Button', {
                props: { type: 'success', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.getExportSetSubList()
                    params.row.disabled = true
                  }
                }
              }, '取消'))
            }
            return h('div', temp)
          }
        }
      ],
      dataList1: [],
      columns2: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '导出设置编号', key: 'export_code', align: 'center' },
        { title: '导出列表名', slot: 'export_table', align: 'center' },
        { title: '导出列', slot: 'export_column', align: 'center' },
        { title: '导出列别名', slot: 'export_column_alias', align: 'center' },
        { title: '导出列标题', slot: 'export_column_name', align: 'center' },
        { title: '导出列字典', slot: 'export_column_dict', align: 'center' },
        { title: '导出列sql', slot: 'export_column_sql', align: 'center' },
        { title: '操作',
          align: 'center',
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'error', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.deleteExportSetDetail(params.row)
                  }
                }
              }, '删除')
            )
            return h('div', temp)
          }
        }
      ],
      dataList2: [],
      columns3: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '导出设置编号', key: 'export_code', align: 'center' },
        { title: '条件列', key: 'export_column', align: 'center' },
        { title: '条件', key: 'export_condition', align: 'center' },
        { title: '操作',
          align: 'center',
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'error', size: 'small' },
                style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                on: {
                  click: () => {
                    this.deleteExportSetCondition(params.row)
                  }
                }
              }, '删除')
            )
            return h('div', temp)
          }
        }
      ],
      dataList3: []
    }
  },
  methods: {
    exportStart () {
      this.$refs.export.show1(true)
    },
    init () {
      let params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        export_state: this.searchData.export_state,
        export_code: this.searchData.export_code,
        export_name: this.searchData.export_name
      }
      getExportSetPageList(params).then(res => {
        if (res.data.errcode === 0) {
          res.data.data.results.forEach(function (temp) {
            temp.disabled = true
            if (temp.export_state === '0') {
              temp.state = '未启用'
            }
            if (temp.export_state === '1') {
              temp.state = '已启用'
            }
          })
          this.dataList = res.data.data.results
          this.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({
            title: '获取数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getExportDataBaseBsList () {
      getExportDataBaseBsList().then(res => {
        if (res.data.errcode === 0) {
          this.dataBaseBsList = res.data.data.list
        } else {
          this.$Notice.error({
            title: '查询数据库标识失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    findTable (param) {
      if (param.id || param.table_schema) {
        let params = {
          export_database_id: param.id,
          table_schema: param.table_schema
        }
        getExportDataBaseBsTableList(params).then(res => {
          if (res.data.errcode === 0) {
            this.dataBaseBsTableList = res.data.data.list
          } else {
            this.$Notice.error({
              title: '查询数据库标识失败',
              desc: res.data.errmsg
            })
          }
        })
      }
    },
    getExportSetTableNameList (param) {
      if (param.export_code) {
        let params = {
          export_code: param.export_code
        }
        getExportSetTableNameList(params).then(res => {
          if (res.data.errcode === 0) {
            this.tableNameList = res.data.data.list
          } else {
            this.$Notice.error({
              title: '查询数据库标识失败',
              desc: res.data.errmsg
            })
          }
        })
      }
    },
    getTableFieldList (export_table) {
      if (export_table) {
        let params = {
          table_schema: this.row.table_schema,
          table_name: export_table,
          export_database: this.row.export_database
        }
        getTableFieldList(params).then(res => {
          if (res.data.errcode === 0) {
            this.fieldList = res.data.data.list
          } else {
            this.$Notice.error({
              title: '查询数据库标识失败',
              desc: res.data.errmsg
            })
          }
        })
      }
    },
    addExportSet () {
      this.modal.title = '添加导出任务'
      this.modal.show = true
      this.modal.type = '1'
      this.formData = {}
      this.export_database = ''
    },
    addExportSetOk () {
      this.formData.export_database = this.export_database
      insertExportSet(this.formData).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '添加成功'
          })
          this.formData = {}
          this.modal.show = false
          this.init()
        } else {
          this.$Notice.error({
            title: '添加数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.init()
    },
    updateExportSetOk () {
      this.formData.export_database = this.export_database
      updateExportSet(this.formData).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '修改成功'
          })
          this.formData = {}
          this.export_database = ''
          this.modal.show = false
          this.init()
        } else {
          this.$Notice.error({
            title: '修改数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    deleteExportSetOk (param) {
      deleteExportSet(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '删除成功'
          })
          this.init()
        } else {
          this.$Notice.error({
            title: '删除数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.init()
    },
    getDataBaseNameList (param) {
      let params = {
        table_schema: param.table_schema
      }
      this.tableData = []
      let that = this
      getDataBaseNameList(params).then(res => {
        if (res.data.errcode === 0) {
          res.data.data.list.forEach(function (temp) {
            let data = {}
            data.key = temp.TABLE_NAME
            data.label = temp.TABLE_COMMENT
            that.tableData.push(data)
          })
          console.log(this.tableData)
        } else {
          this.$Notice.error({
            title: '获取数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getExportSetSubList (param) {
      this.dataList1 = []
      let params = {
        export_code: this.row.export_code
      }
      getExportSetSubList(params).then(res => {
        if (res.data.errcode === 0) {
          res.data.data.list.forEach(function (temp) {
            temp.disabled = true
          })
          this.dataList1 = res.data.data.list
        } else {
          this.$Notice.error({
            title: '获取数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    updateExportSetSubOk () {
      updateExportSetSub(this.formData1).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '修改成功'
          })
        } else {
          this.$Notice.error({
            title: '修改数据失败',
            desc: res.data.errmsg
          })
        }
        this.formData1 = {}
        this.getExportSetSubList()
      })
    },
    addSubTable () {
      // this.addTableModal.show = true
      // this.getDataBaseNameList(this.row)
      let data = {
        export_code: this.row.export_code
      }
      this.dataList1.push(data)
    },
    addSetDetail () {
      this.modal1.show = true
      this.getExportSetTableNameList(this.row)
      // this.getDataBaseNameList(this.row)
      // let data = {
      //   export_code: this.row.export_code
      // }
      // this.dataList2.push(data)
    },
    addSetCondition () {
      this.modal2.show = true
      // this.getExportSetTableNameList(this.row)
      // this.getDataBaseNameList(this.row)
      // let data = {
      //   export_code: this.row.export_code
      // }
      // this.dataList2.push(data)
    },
    addExportSetSubOk () {
      insertExportSetSub(this.formData1).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '添加成功'
          })
          this.formData1 = {}
          this.getExportSetSubList()
        } else {
          this.$Notice.error({
            title: '添加数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.formData1 = {}
      this.getExportSetSubList()
    },
    addExportSetConditionOk () {
      this.formData2.export_code = this.row.export_code
      insertExportSetCondition(this.formData2).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '添加成功'
          })
          this.modal2.show = false
          this.getExportSetConditionList()
        } else {
          this.$Notice.error({
            title: '添加数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.formData2 = {}
      this.getExportSetConditionList()
    },
    deleteExportSetCondition (param) {
      deleteExportSetCondition(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '删除成功'
          })
          this.getExportSetConditionList()
        } else {
          this.$Notice.error({
            title: '删除数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.getExportSetDetailList()
    },
    addExportSetDetailOk () {
      this.formData1.export_table = this.export_table
      this.formData1.export_select_column = this.export_select_column
      this.formData1.export_column = this.export_column
      this.formData1.export_column_alias = this.export_column_alias
      this.formData1.export_code = this.row.export_code
      insertExportSetDetail(this.formData1).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '添加成功'
          })
          this.modal1.show = false
          this.getExportSetDetailList()
        } else {
          this.$Notice.error({
            title: '添加数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.formData1 = {}
      this.export_select_column = ''
      this.export_table = ''
      this.export_column = ''
      this.export_column_alias = ''
      this.getExportSetDetailList()
    },
    deleteExportSetSubOk (param) {
      deleteExportSetSub(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '删除成功'
          })
          this.getExportSetSubList()
        } else {
          this.$Notice.error({
            title: '删除数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.getExportSetSubList()
    },
    deleteExportSetDetail (param) {
      deleteExportSetDetail(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success({
            background: true,
            content: '删除成功'
          })
          this.getExportSetDetailList()
        } else {
          this.$Notice.error({
            title: '删除数据失败',
            desc: res.data.errmsg
          })
        }
      })
      this.getExportSetDetailList()
    },
    getExportSetDetailList (param) {
      this.dataList2 = []
      let params = {
        export_code: this.row.export_code
      }
      getExportSetDetailList(params).then(res => {
        if (res.data.errcode === 0) {
          res.data.data.list.forEach(function (temp) {
            temp.disabled = true
          })
          this.dataList2 = res.data.data.list
        } else {
          this.$Notice.error({
            title: '获取数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getExportSetConditionList (param) {
      this.dataList3 = []
      let params = {
        export_code: this.row.export_code
      }
      getExportSetConditionList(params).then(res => {
        if (res.data.errcode === 0) {
          this.dataList3 = res.data.data.list
        } else {
          this.$Notice.error({
            title: '获取数据失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    handleChange (newTargetKeys, direction, moveKeys) {
      this.targetKeys = newTargetKeys
      console.log(newTargetKeys, 'newTargetKeys')
      console.log(direction, 'direction')
      console.log(moveKeys, 'moveKeys')
    },
    render (item) {
      return item.key + '\t' + item.label
    },
    changePagesize (pageSize) {
      this.pageSize = pageSize
      this.changePageNo()
    },
    changePageNo (pageNo) {
      this.pageNo = pageNo
      this.init()
    },
    changePagesize1 (pageSize) {
      this.pageSize1 = pageSize
      this.changePageNo1()
    },
    changePageNo1 (pageNo) {
      this.pageNo1 = pageNo
      this.getExportSetSubList()
    },
    indexChange (index) {
      this.index = index
    },
    columnOnChange (val) {
      this.formData2.export_condition = val
    }
  },
  watch: {
    export_database (val) {
      let data = {}
      let that = this
      this.dataBaseBsList.forEach(function (temp) {
        if (temp.export_database === val) {
          data = temp
          that.formData.table_schema = temp.table_schema
        }
      })
      this.findTable(data)
    },
    export_table (val) {
      let data = {}
      let that = this
      this.tableNameList.forEach(function (temp) {
        if (temp.tablename === val) {
          data = temp
          that.export_tableObj = temp.tablename
          data.export_table = temp.tablename
        }
      })
      this.tableObj = data
      this.getTableFieldList(val)
    },
    export_column (val) {
      if (val && this.export_column_alias) {
        this.formData1.export_column_sql = val + ' ' + 'AS' + ' ' + this.export_column_alias
      } else {
        this.formData1.export_column_sql = ''
      }
    },
    export_column_alias (val) {
      if (val && this.export_column) {
        this.formData1.export_column_sql = this.export_column + ' ' + 'AS' + ' ' + val
      } else {
        this.formData1.export_column_sql = ''
      }
    },
    export_select_column (val) {
      if (val) {
        let that = this
        this.export_column = this.tableObj.tablealias + '.' + val
        this.fieldList.forEach(function (temp) {
          if (temp.COLUMN_NAME === val) {
            that.formData1.export_column_type = temp.DATA_TYPE
          }
        })
        console.log(this.formData1)
      } else {
        this.export_column = ''
      }
    }
  },
  mounted () {
    this.init()
    this.getExportDataBaseBsList()
  }
}
</script>
